<?php

namespace App\Crontab;

use App\Model\Mysql\OnlineOrderModel;
use App\Model\Mysql\UserIntegralModel;
use App\Service\OrderService;
use EasySwoole\EasySwoole\Crontab\AbstractCronTask;
use EasySwoole\EasySwoole\Task\TaskManager;

class Integral extends AbstractCronTask
{

    public static function getRule(): string
    {
        return '59 23 * * *';
    }

    public static function getTaskName(): string
    {
        return 'integral';
    }

    /**
     * 签到归零
     * @param int $taskId
     * @param int $workerIndex
     */
    function run(int $taskId, int $workerIndex)
    {
        $data = UserIntegralModel::getList(['num' => 7], ['id']);
        foreach ($data as $value) {
            UserIntegralModel::editData(['num' => 0, 'take_num' => 0, 'freight_num' => 0], ['id' => $value['id']]);
        }
    }

    function onException(\Throwable $throwable, int $taskId, int $workerIndex)
    {
        echo $throwable->getMessage();
    }
}
